public class Day10 {
    public static void main(String[] args) {

    }
    boolean[][] check;
    int max,m,n,count;
    public int maxAreaOfIsland(int[][] grid) {
        max = 0;
        m=grid.length;
        n=grid[0].length;
        check = new boolean[m][n];
        for(int i=0;i<m;i++) {
            for(int j=0;j<n;j++) {
                if(grid[i][j]==1&&check[i][j]==false) {
                    floodfill(grid,i,j);
                    count=0;
                }
            }
        }
        return max;
    }
    public void floodfill(int[][] grid,int i,int j) {
        check[i][j]=true;
        count++;
        //上，下，左，右
        if(i-1>=0 && grid[i-1][j]==1&&check[i-1][j]==false) {
            floodfill(grid,i-1,j);
        }
        if(i+1<m && grid[i+1][j]==1&&check[i+1][j]==false) {
            floodfill(grid,i+1,j);
        }
        if(j-1>=0 && grid[i][j-1]==1&&check[i][j-1]==false) {
            floodfill(grid,i,j-1);
        }
        if(j+1<n && grid[i][j+1]==1&&check[i][j+1]==false) {
            floodfill(grid,i,j+1);
        }
        max = Math.max(max,count);
    }
}
